package main

import (
	"fmt"
	"sync"
)

var (
	counter int
	mutex   sync.Mutex
	rwMutex sync.RWMutex
)

func increment() {
	mutex.Lock()
	defer mutex.Unlock()
	counter++
	fmt.Println("increment mutex Counter:", counter)
}

func read() {
	rwMutex.Lock()
	defer rwMutex.Unlock()
	fmt.Println("read rwMutex Counter:", counter)
}

func main() {
	var wg sync.WaitGroup
	numGoroutines := 1000

	wg.Add(numGoroutines)
	for i := 0; i < numGoroutines; i++ {
		go func() {
			defer wg.Done()
			read()
			increment()
		}()
	}

	wg.Wait()
	wg.Add(1)
	fmt.Println("Counter:", counter)
}
